package net.entelijan.cobean.examples.showcase.bind.text;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.entelijan.scf.DefaultShowcasePanel;
import net.miginfocom.swing.MigLayout;

public class DoubleBindTextPanel extends DefaultShowcasePanel {

	private JTextField nameUpTextField = new JTextField();
	private JTextField birthdayUpTextField = new JTextField();
	private JTextField idUpTextField = new JTextField();

	private JTextComponent nameFailureUpTextField = createFailureComponent();
	private JTextComponent birthdayFailureUpTextField = createFailureComponent();
	private JTextComponent idFailureUpTextField = createFailureComponent();

	private JTextField nameDownTextField = new JTextField();
	private JTextField birthdayDownTextField = new JTextField();
	private JTextField idDownTextField = new JTextField();

	private JTextComponent nameFailureDownTextField = createFailureComponent();
	private JTextComponent birthdayFailureDownTextField = createFailureComponent();
	private JTextComponent idFailureDownTextField = createFailureComponent();

	private JButton resetButton = new JButton("Reset");
	private JButton showObjectButton = new JButton("Show Model");
	private JButton uppercaseButton = new JButton("Uppercase");
	private JButton lowercaseButton = new JButton("Lowercase");

	private static final long serialVersionUID = 1L;

	public DoubleBindTextPanel() {
		super();
		// Layout the components
		setLayout(new MigLayout());

		add(new JLabel("Name"), "w 150");
		add(nameUpTextField, "w 200:200:200");
		add(nameFailureUpTextField, "w max, grow, wrap");
		add(new JLabel("Birthday"), "w 150");
		add(birthdayUpTextField, "w 200:200:200");
		add(birthdayFailureUpTextField, "w max, grow, wrap");
		add(new JLabel("ID"), "w 150");
		add(idUpTextField, "w 200:200:200");
		add(idFailureUpTextField, "w max, grow, wrap");

		add(new JSeparator(), "span 3, w max, wrap");

		add(new JLabel("Name"), "w 150");
		add(nameDownTextField, "w 200:200:200");
		add(nameFailureDownTextField, "w max, grow, wrap");
		add(new JLabel("Birthday"), "w 150");
		add(birthdayDownTextField, "w 200:200:200");
		add(birthdayFailureDownTextField, "w max, grow, wrap");
		add(new JLabel("ID"), "w 150");
		add(idDownTextField, "w 200:200:200");
		add(idFailureDownTextField, "w max, grow, wrap");

		add(new JPanel(), "span 3, h max, grow, w max, wrap");
		add(ExamplesUtil.createButtonsPanel(100, this.resetButton,
				this.showObjectButton, this.uppercaseButton,
				this.lowercaseButton), "span 3");
	}

	// Create a failure component
	private JTextComponent createFailureComponent() {
		JTextField re = new JTextField();
		re.setEditable(false);
		re.setForeground(Color.RED);
		re.setFocusable(false);
		re.setBorder(null);
		return re;
	}

	// Setters and getters for all components

	public JButton getShowObjectButton() {
		return showObjectButton;
	}

	public void setShowObjectButton(JButton showSelectedButton) {
		this.showObjectButton = showSelectedButton;
	}

	public JButton getUppercaseButton() {
		return uppercaseButton;
	}

	public void setUppercaseButton(JButton uppercaseButton) {
		this.uppercaseButton = uppercaseButton;
	}

	public JButton getLowercaseButton() {
		return lowercaseButton;
	}

	public void setLowercaseButton(JButton lowercaseButton) {
		this.lowercaseButton = lowercaseButton;
	}

	public JButton getResetButton() {
		return resetButton;
	}

	public void setResetButton(JButton resetButton) {
		this.resetButton = resetButton;
	}

	public JTextField getNameUpTextField() {
		return nameUpTextField;
	}

	public void setNameUpTextField(JTextField nameUpTextField) {
		this.nameUpTextField = nameUpTextField;
	}

	public JTextField getBirthdayUpTextField() {
		return birthdayUpTextField;
	}

	public void setBirthdayUpTextField(JTextField birthdayUpTextField) {
		this.birthdayUpTextField = birthdayUpTextField;
	}

	public JTextField getIdUpTextField() {
		return idUpTextField;
	}

	public void setIdUpTextField(JTextField idUpTextField) {
		this.idUpTextField = idUpTextField;
	}

	public JTextComponent getNameFailureUpTextField() {
		return nameFailureUpTextField;
	}

	public void setNameFailureUpTextField(JTextComponent nameFailureUpTextField) {
		this.nameFailureUpTextField = nameFailureUpTextField;
	}

	public JTextComponent getBirthdayFailureUpTextField() {
		return birthdayFailureUpTextField;
	}

	public void setBirthdayFailureUpTextField(
			JTextComponent birthdayFailureUpTextField) {
		this.birthdayFailureUpTextField = birthdayFailureUpTextField;
	}

	public JTextComponent getIdFailureUpTextField() {
		return idFailureUpTextField;
	}

	public void setIdFailureUpTextField(JTextComponent idFailureUpTextField) {
		this.idFailureUpTextField = idFailureUpTextField;
	}

	public JTextField getNameDownTextField() {
		return nameDownTextField;
	}

	public void setNameDownTextField(JTextField nameDownTextField) {
		this.nameDownTextField = nameDownTextField;
	}

	public JTextField getBirthdayDownTextField() {
		return birthdayDownTextField;
	}

	public void setBirthdayDownTextField(JTextField birthdayDownTextField) {
		this.birthdayDownTextField = birthdayDownTextField;
	}

	public JTextField getIdDownTextField() {
		return idDownTextField;
	}

	public void setIdDownTextField(JTextField idDownTextField) {
		this.idDownTextField = idDownTextField;
	}

	public JTextComponent getNameFailureDownTextField() {
		return nameFailureDownTextField;
	}

	public void setNameFailureDownTextField(
			JTextComponent nameFailureDownTextField) {
		this.nameFailureDownTextField = nameFailureDownTextField;
	}

	public JTextComponent getBirthdayFailureDownTextField() {
		return birthdayFailureDownTextField;
	}

	public void setBirthdayFailureDownTextField(
			JTextComponent birthdayFailureDownTextField) {
		this.birthdayFailureDownTextField = birthdayFailureDownTextField;
	}

	public JTextComponent getIdFailureDownTextField() {
		return idFailureDownTextField;
	}

	public void setIdFailureDownTextField(JTextComponent idFailureDownTextField) {
		this.idFailureDownTextField = idFailureDownTextField;
	}

}
